export const diGui = (data: any) => {
  data.forEach((item: any) => {
    item.value = item.id
    item.label = item.name
    if (item.children !== undefined) {
      diGui(item.children)
    }
  })
  return data
}

// 递归回显
export const diGuiHx = (key: any, treeData:any) => {
  let arr: any = [] // 在递归时操作的数组
  let returnArr: any = [] // 存放结果的数组
  let num = 0 // 定义全局层级
  // 定义递归函数
  function childrenEach (childrenData: any, nums: any) {
    for (let j = 0; j < childrenData.length; j++) {
      num = nums // 将执行的层级赋值 到 全局层级
      arr[nums] = childrenData[j].id
      if (childrenData[j].id === key) {
        returnArr = arr.slice(0, nums + 1) // 将目前匹配的数组，截断并保存到结果数组，
        break
      } else {
        if (childrenData[j].children) {
          num++
          childrenEach(childrenData[j].children, num)
        }
      }
    }
    return returnArr
  }
  return childrenEach(treeData, num)
}